import java.util.Arrays;
import java.util.Scanner;


public class Main {


    //空调遥控
    public static void main(String[] args) {
        Scanner in= new Scanner(System.in);
        int n = in.nextInt();
        int p = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        Arrays.sort(arr);
        int left = 0,right = 0,ret = 0;
        p*=2;
        while (right<n){
            while(arr[right]-arr[left]>p){
                left++;
            }
            ret = Math.max(ret,right-left+1);
            right++;
        }
        System.out.println(ret);
    }


    //不相邻取数
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n+1];
        int[] f = new int[n+1];
        int[] g = new int[n+1];

        for (int i = 1; i <= n; i++) {
            arr[i] = in.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            f[i] = g[i-1]+arr[i];
            g[i] = Math.max(f[i-1],g[i-1]);
        }
        System.out.println(Math.max(f[n],g[n]));

    }

    //小红的ABC
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] s = in.next().toCharArray();

        int ret = -1;
        int n = s.length;
        for (int i = 0; i < n; i++) {
            if(i+1 <n && s[i] == s[i+1]){
                ret=2;
                break;
            }
            if (i+2 <n && s[i] == s[i+2]){
                ret = 3;
            }
        }
        System.out.println(ret);
    }
}
